import React, { useEffect, useState, useRef } from 'react';
import { connect } from 'umi';
import { Form, Button, Card, Input, InputNumber, Popover, notification } from 'antd';
import EditorForm from '@/components/EditorForm';
import FormCondition from '@/components/FormCondition';
import FlxButton from '@/components/FlxButton'
import { InfoCircleOutlined } from '@ant-design/icons'
import { Row, Col, Tooltip, Space } from 'antd'
import SetAdminList from '@/components/setAdminList'

const bindAdminSet = (props) => {
    const { dispatch, reload } = props;
    const [params, setParams] = useState({
        assignAdminFlag: '0'
    })
    const [list, setList] = useState([])
    const [data, setData] = useState({})
    const [form] = Form.useForm();
    const fetchData = () => {

    }
    const { assignAdminFlag } = params
    // 新增修改 传id修改 不传id新增=
    const fetchRoleEdit = () => {
        if (assignAdminFlag === '1' && list.length === 0) {
            return notification.warning({
                message: '错误提示',
                description: '请设置绑定员工',
            })
        }
        form.validateFields().then((values) => {
            dispatch({
                type: 'promoter/fakeSetAssignAdmin',
                payload: {
                    ...values,
                    assignAdminIds: list.map(item => {
                        return item.id
                    }).toString()
                },
                callback: () => {
                    fetchData()
                }
            })
        });
    };
    useEffect(() => {
        fetchData()
    }, [])

    const formItemLayout = {
        labelCol: {
            sm: { span: 0 },
        },
        wrapperCol: {
            sm: { span: 0 },
        },
    };
    const formItems = [
        {
            label: '是否绑定员工',
            name: 'assignAdminFlag',
            onChange: (e) => {
                setList([])
                setParams({
                    assignAdminFlag: e.target.value
                })
            },
            type: 'radio',
            select: {
                0: '否',
                1: '是',
            },
        },
        {
            visible: assignAdminFlag == '1',
            type: 'noForm',
            formItem: <SetAdminList list={list} setList={setList}></SetAdminList>
        },
    ];


    return (
        <div style={{ fontSize: 28 }}>
            <Row>
                <Col span={18}>
                    <div style={{ paddingTop: 12 }}>
                        <FormCondition formItemLayouts={formItemLayout} form={form} formItems={formItems} initialValues={{ assignAdminFlag: '0' }}></FormCondition>
                    </div>
                </Col>
                <FlxButton onOk={fetchRoleEdit}></FlxButton>
            </Row>
        </div>
    );
};

export default connect(({ institution, loading }) => ({
    loading: loading.models.institution,
}))(bindAdminSet);
